package khannedy.blogging.masterdetail.model;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import khannedy.blogging.masterdetail.entity.MataKuliah;

public class TableModelMataKuliah extends AbstractTableModel {

    private List<MataKuliah> list = new ArrayList<MataKuliah>();

    public void setList(List<MataKuliah> list) {
        this.list = list;
        fireTableDataChanged();
    }

    public int getRowCount() {
        return list.size();
    }

    public int getColumnCount() {
        return 4;//Edited by Jasoet 
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "Kode";
            case 1:
                return "Nama";
            //Added by Jasoet [start]
            case 2:
                return "SKS";
            case 3:
                return "Biaya";
            //Added by Jasoet [end]
            default:
                return null;
        }
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case 0:
                return list.get(rowIndex).getKode();
            case 1:
                return list.get(rowIndex).getNama();
            //Added by Jasoet [start]
            case 2:
                return list.get(rowIndex).getSks();
            case 3:
                return list.get(rowIndex).getBiaya();
            //Added by Jasoet [end]
            default:
                return null;
        }
    }

    //Added by Jasoet [start]
    @Override
    public Class<?> getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case 0:
                return String.class;
            case 1:
                return String.class;
            case 2:
                return Integer.class;
            case 3:
                return Double.class;
            default:
                return null;
        }
    }
    //Added by Jasoet [end]
}
